package edu.dayu.iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MyIterator<T> implements Iterable{
    private List<T> list = new ArrayList<>();

    public boolean add(T t){
        return list.add(t);
    }

    public boolean remove(T t){
        return list.remove(t);
    }

    @Override
    public Iterator iterator() {
        return new MyItr();
    }


    private class MyItr implements Iterator {
        int index = 0;
        @Override
        public boolean hasNext() {
            if (index< list.size()){
                return true;
            }
            return false;
        }

        @Override
        public T next() {
            T t = list.get(index);
            index++;
            return t;
        }
    }
}
